using System;
using System.Collections.Generic;
using System.Text;
using System.Reflection;

namespace ESnatch
{
    public class OutputMapping
    {
        static string[] TranslatableTypes = { "String", "DateTime", "Boolean", "Int32" };
        static string[] DefaultOutputTypes = { "Text", "Date/Time", "Yes/No", "Integer" };

        string m_targetType;        
        bool m_bInclude;
        PropertyInfo m_pInfo;
        public OutputMapping(PropertyInfo pinfo)
        {
            m_pInfo = pinfo;
            Type propType = pinfo.PropertyType;
            m_targetType = "Text";
            m_bInclude = true;
            if (!IsMappable)
            {
                m_targetType = "N/A";
                m_bInclude = false;
            }
        }

        public static string[] getTranslatableTypes()
        {
            return TranslatableTypes;
        }

        public static string[] getDefaultOutputTypes()
        {
            return DefaultOutputTypes;
        }

        public PropertyInfo SrcPropInfo
        {
            get
            {
                return m_pInfo;
            }
        }

        public bool IsMappable
        {
            get
            {
                Type propType = m_pInfo.PropertyType;
                return isStringInset(propType.Name, TranslatableTypes);
            }
        }

        public string TargetType
        {
            get
            {
                return m_targetType;
            }
            set
            {
                m_targetType = value;
            }
        }

        public string IncludeTxt
        {
            get
            {
                if (m_bInclude)
                    return "Yes";
                else
                   return "No";
            }
        }

        public bool Include
        {
            get {
                return m_bInclude;
            }
            set {
                m_bInclude = value;
            }
        }

        private bool isStringInset(string testStr, string[] set)
        {
            for (int ix = 0; ix < set.Length; ix++)
            {
                if (testStr.CompareTo(set[ix]) == 0)
                    return true;
            }
            return false;
        }

    }
}
